package Leetcode第一期;

import java.util.*;

/**
 * @author : K k
 * @date : 20:19 2020/9/8
 */
public class 包含min函数的栈_30 {

    static class MinStack {

        Stack<Integer> stackA;
        Stack<Integer> stackB;

        /** initialize your data structure here. */
        public MinStack() {
            this.stackA=new Stack<>();
            this.stackB=new Stack<>();
        }

        public void push(int x) {
            stackA.add(x);
            if (stackB.isEmpty() || stackB.peek()>=x){
                stackB.add(x);
            }
        }

        public void pop() {
            if (stackA.pop().equals(stackB.peek())) {stackB.pop();}
        }

        public int top() {
            return stackA.peek();
        }

        public int min() {
            return stackB.peek();
        }
    }

    public static void main(String[] args) {
        Deque<Integer> deque= new ArrayDeque<>();
        deque.push(-2);
        deque.push(-3);
        deque.removeFirst();
        System.out.println(deque);

        /*MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.min());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.min());*/

    }
}
